using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Rep
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class RGD : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label2;
        private TextBox txtNAME;
        private TextBox txtDAG_ID;
        private Label label1;
        private Label label7;
        private DataGridView dgvList;
        private Label label5;
        private Label label4;
        private Button btnRemove;
        private Button btnClear;
        private Button btnAdd;
        private Button btnFill;
        private ListView libDataAccessGroup;
        private ListView libGroup;
        private DataGridViewTextBoxColumn colNAME;
        private IContainer components;
        private ComboBox cboDA;
        GridLayout layout = null;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn6;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn7;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn8;
        private BindingSource bisDA;
        private ColumnHeader colDescription;
        private ColumnHeader colCODE;
        //private ColumnHeader colDescription1;
        private DTO.PODInfo PODInfo;
        public RGD()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();
            _strType = "RGD";

            PODInfo = (DTO.PODInfo)Session["USER"];

        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        int idAllowEditLanguage = 1;
        int idAddNew = 157;
        int idEdit = 158;
        int idDelete = 159;
        int idTransferIn = 160;
        int idTransferOut = 161;
        int idPrint = 162;

        private string _DB = "TVC";
        private bool _isValueChange = true;




        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Language"));
            dgvList.MenuClick += dgvList_MenuClick;
            tabControl1.DoubleClick += tabMain_DoubleClick;
            dgvList.ContextMenu = menu;
        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }
            //clsConfigurarion.GetLabel(this.ToString(), lbUserID, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDescription, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblLanguage, language);
            //clsConfigurarion.GetLabel(this.ToString(), lblDbDefault, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklRole, language);
            //clsConfigurarion.GetLabel(this.ToString(), lklEmp, language);

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            objElements.Add(new HostedToolBarSeperator());
            ////if (IsPermis(idTransferIn))
            ////    objElements.Add(new HostedToolBarButton("clsTransfer In", new IconResourceHandle("Down.png"), "TI"));
            ////if (IsPermis(idTransferOut))
            ////    objElements.Add(new HostedToolBarButton("clsTransfer Out", new IconResourceHandle("Up.png"), "TO"));
            ////objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idPrint))
                objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }

        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            Gizmox.WebGUI.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new Gizmox.WebGUI.Forms.DataGridViewCellStyle();
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.dataGridViewTextBoxColumn1 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn2 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn3 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn4 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn5 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn6 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn7 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.dataGridViewTextBoxColumn8 = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.bisDA = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.cboDA = new Gizmox.WebGUI.Forms.ComboBox();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.btnRemove = new Gizmox.WebGUI.Forms.Button();
            this.btnClear = new Gizmox.WebGUI.Forms.Button();
            this.btnAdd = new Gizmox.WebGUI.Forms.Button();
            this.btnFill = new Gizmox.WebGUI.Forms.Button();
            this.libDataAccessGroup = new Gizmox.WebGUI.Forms.ListView();
            this.colCODE = ((Gizmox.WebGUI.Forms.ColumnHeader)(new Gizmox.WebGUI.Forms.ColumnHeader()));
            this.colDescription = ((Gizmox.WebGUI.Forms.ColumnHeader)(new Gizmox.WebGUI.Forms.ColumnHeader()));
            this.libGroup = new Gizmox.WebGUI.Forms.ListView();
            this.label7 = new Gizmox.WebGUI.Forms.Label();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtNAME = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDAG_ID = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            this.colNAME = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.SuspendLayout();
            // 
            // errProvider
            // 
            this.errProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // warnProvider
            // 
            this.warnProvider.BlinkStyle = Gizmox.WebGUI.Forms.ErrorBlinkStyle.BlinkIfDifferentError;
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.ClientBehavior = Gizmox.WebGUI.Forms.TabControlClientBehavior.DrawingOptimized;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(820, 470);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(812, 444);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowDrag = false;
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)((((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Bottom) 
            | Gizmox.WebGUI.Forms.AnchorStyles.Left) 
            | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.dataGridViewTextBoxColumn1,
            this.dataGridViewTextBoxColumn2,
            this.dataGridViewTextBoxColumn3,
            this.dataGridViewTextBoxColumn4,
            this.dataGridViewTextBoxColumn5,
            this.dataGridViewTextBoxColumn6,
            this.dataGridViewTextBoxColumn7,
            this.dataGridViewTextBoxColumn8});
            this.dgvList.DataSource = this.bisDA;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            this.dgvList.RowHeaderMouseDoubleClick += new Gizmox.WebGUI.Forms.DataGridViewCellMouseEventHandler(this.dgvList_RowHeaderMouseDoubleClick);
            // 
            // dataGridViewTextBoxColumn1
            // 
            this.dataGridViewTextBoxColumn1.DataPropertyName = "DB";
            this.dataGridViewTextBoxColumn1.DefaultCellStyle = dataGridViewCellStyle1;
            this.dataGridViewTextBoxColumn1.HeaderText = "DB";
            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            this.dataGridViewTextBoxColumn1.Visible = false;
            // 
            // dataGridViewTextBoxColumn2
            // 
            this.dataGridViewTextBoxColumn2.DataPropertyName = "ReportGroup";
            this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle2;
            this.dataGridViewTextBoxColumn2.HeaderText = "ReportGroup";
            this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
            this.dataGridViewTextBoxColumn2.Width = 200;
            // 
            // dataGridViewTextBoxColumn3
            // 
            this.dataGridViewTextBoxColumn3.DataPropertyName = "Name";
            this.dataGridViewTextBoxColumn3.DefaultCellStyle = dataGridViewCellStyle3;
            this.dataGridViewTextBoxColumn3.HeaderText = "Name";
            this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
            this.dataGridViewTextBoxColumn3.Width = 200;
            // 
            // dataGridViewTextBoxColumn4
            // 
            this.dataGridViewTextBoxColumn4.DataPropertyName = "DAGid";
            this.dataGridViewTextBoxColumn4.DefaultCellStyle = dataGridViewCellStyle4;
            this.dataGridViewTextBoxColumn4.HeaderText = "DAGid";
            this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
            this.dataGridViewTextBoxColumn4.Width = 200;
            // 
            // dataGridViewTextBoxColumn5
            // 
            this.dataGridViewTextBoxColumn5.DataPropertyName = "Createdby";
            this.dataGridViewTextBoxColumn5.DefaultCellStyle = dataGridViewCellStyle5;
            this.dataGridViewTextBoxColumn5.HeaderText = "Createdby";
            this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
            this.dataGridViewTextBoxColumn5.Visible = false;
            // 
            // dataGridViewTextBoxColumn6
            // 
            this.dataGridViewTextBoxColumn6.DataPropertyName = "Insertpointoftime";
            this.dataGridViewTextBoxColumn6.DefaultCellStyle = dataGridViewCellStyle6;
            this.dataGridViewTextBoxColumn6.HeaderText = "Insertpointoftime";
            this.dataGridViewTextBoxColumn6.Name = "dataGridViewTextBoxColumn6";
            this.dataGridViewTextBoxColumn6.Visible = false;
            // 
            // dataGridViewTextBoxColumn7
            // 
            this.dataGridViewTextBoxColumn7.DataPropertyName = "Updatedby";
            this.dataGridViewTextBoxColumn7.DefaultCellStyle = dataGridViewCellStyle7;
            this.dataGridViewTextBoxColumn7.HeaderText = "Updatedby";
            this.dataGridViewTextBoxColumn7.Name = "dataGridViewTextBoxColumn7";
            this.dataGridViewTextBoxColumn7.Visible = false;
            // 
            // dataGridViewTextBoxColumn8
            // 
            this.dataGridViewTextBoxColumn8.DataPropertyName = "Lastupdate";
            this.dataGridViewTextBoxColumn8.DefaultCellStyle = dataGridViewCellStyle8;
            this.dataGridViewTextBoxColumn8.HeaderText = "Lastupdate";
            this.dataGridViewTextBoxColumn8.Name = "dataGridViewTextBoxColumn8";
            this.dataGridViewTextBoxColumn8.Visible = false;
            // 
            // bisDA
            // 
            this.bisDA.DataSource = typeof(DTO.csreportgroupsInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.cboDA);
            this.tbDetail.Controls.Add(this.label5);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.btnRemove);
            this.tbDetail.Controls.Add(this.btnClear);
            this.tbDetail.Controls.Add(this.btnAdd);
            this.tbDetail.Controls.Add(this.btnFill);
            this.tbDetail.Controls.Add(this.libDataAccessGroup);
            this.tbDetail.Controls.Add(this.libGroup);
            this.tbDetail.Controls.Add(this.label7);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtNAME);
            this.tbDetail.Controls.Add(this.txtDAG_ID);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(812, 444);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // cboDA
            // 
            this.cboDA.AllowDrag = false;
            this.cboDA.AutoCompleteMode = Gizmox.WebGUI.Forms.AutoCompleteMode.SuggestAppend;
            this.cboDA.DropDownWidth = 200;
            this.cboDA.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboDA.FormattingEnabled = true;
            this.cboDA.Location = new System.Drawing.Point(130, 61);
            this.cboDA.MaximumSize = new System.Drawing.Size(400, 20);
            this.cboDA.Name = "cboDA";
            this.cboDA.Size = new System.Drawing.Size(145, 20);
            this.cboDA.TabIndex = 5;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(438, 94);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(56, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Report Group";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 94);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(56, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Report";
            // 
            // btnRemove
            // 
            this.btnRemove.Location = new System.Drawing.Point(377, 212);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(56, 23);
            this.btnRemove.TabIndex = 7;
            this.btnRemove.Text = "<";
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(377, 252);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(56, 23);
            this.btnClear.TabIndex = 8;
            this.btnClear.Text = "<<";
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(377, 172);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(56, 23);
            this.btnAdd.TabIndex = 6;
            this.btnAdd.Text = ">";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnFill
            // 
            this.btnFill.Location = new System.Drawing.Point(377, 132);
            this.btnFill.Name = "btnFill";
            this.btnFill.Size = new System.Drawing.Size(56, 23);
            this.btnFill.TabIndex = 5;
            this.btnFill.Text = ">>";
            this.btnFill.Click += new System.EventHandler(this.btnFill_Click);
            // 
            // libDataAccessGroup
            // 
            this.libDataAccessGroup.CheckBoxes = true;
            this.libDataAccessGroup.Columns.AddRange(new Gizmox.WebGUI.Forms.ColumnHeader[] {
            this.colCODE,
            this.colDescription});
            this.libDataAccessGroup.DataMember = null;
            this.libDataAccessGroup.Location = new System.Drawing.Point(441, 107);
            this.libDataAccessGroup.Name = "libDataAccessGroup";
            this.libDataAccessGroup.Size = new System.Drawing.Size(350, 323);
            this.libDataAccessGroup.TabIndex = 4;
            // 
            // colCODE
            // 
            this.colCODE.Text = "CODE";
            this.colCODE.Type = Gizmox.WebGUI.Forms.ListViewColumnType.Control;
            this.colCODE.Width = 120;
            // 
            // colDescription
            // 
            this.colDescription.Text = "Description";
            this.colDescription.Type = Gizmox.WebGUI.Forms.ListViewColumnType.Control;
            this.colDescription.Width = 235;
            // 
            // libGroup
            // 
            this.libGroup.CheckBoxes = true;
            this.libGroup.Columns.AddRange(new Gizmox.WebGUI.Forms.ColumnHeader[] {
            this.colCODE,
            this.colDescription});
            this.libGroup.DataMember = null;
            this.libGroup.Location = new System.Drawing.Point(19, 107);
            this.libGroup.Name = "libGroup";
            this.libGroup.Size = new System.Drawing.Size(350, 323);
            this.libGroup.TabIndex = 3;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(16, 64);
            this.label7.Name = "label6";
            this.label7.Size = new System.Drawing.Size(56, 13);
            this.label7.TabIndex = 0;
            this.label7.Text = "Data Access Group";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 39);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Name";
            // 
            // txtNAME
            // 
            this.txtNAME.AllowDrag = false;
            this.txtNAME.Location = new System.Drawing.Point(130, 36);
            this.txtNAME.MaxLength = 100;
            this.txtNAME.Name = "txtNAME";
            this.txtNAME.Size = new System.Drawing.Size(329, 20);
            this.txtNAME.TabIndex = 1;
            // 
            // txtDAG_ID
            // 
            this.txtDAG_ID.AllowDrag = false;
            this.txtDAG_ID.Location = new System.Drawing.Point(130, 12);
            this.txtDAG_ID.MaxLength = 15;
            this.txtDAG_ID.Name = "txtDAG_ID";
            this.txtDAG_ID.Size = new System.Drawing.Size(100, 20);
            this.txtDAG_ID.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Report Group";
            // 
            // colNAME
            // 
            this.colNAME.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colNAME.DataPropertyName = "NAME";
            this.colNAME.DefaultCellStyle = dataGridViewCellStyle9;
            this.colNAME.HeaderText = "Description";
            this.colNAME.Name = "colNAME";
            // 
            // RGD
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -22);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(826, 476);
            this.Load += new System.EventHandler(this.RGD_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDA)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }
        public void addRecord()
        {

        }
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;
                BUS.LIST_DAOGControl daogCtr = new BUS.LIST_DAOGControl();
                BUS.csreportgroupsControl ctr = new BUS.csreportgroupsControl();
                BUS.csreportgroupdetailControl ctrdel = new BUS.csreportgroupdetailControl();
                switch (strAction)
                {
                    case "C":
                        tabControl1.SelectedTab = tbDetail;
                        RefreshForm("");
                        EnableForm(true);
                        break;
                    case "A":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.csreportgroupsInfo info = new DTO.csreportgroupsInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            if (txtDAG_ID.Text != info.ReportGroup)
                                SetData(info);
                            EnableForm(true);
                            txtDAG_ID.ReadOnly = true;
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "S":
                        if (layout == null)
                            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
                        layout.GetUpDGV(dgvList);
                        layout.SaveLayout();
                        Save(ctrdel, ctr);

                        break;
                    case "O":
                        if (dgvList.CurrentCell != null)
                        {
                            if (txtDAG_ID.Text == "")
                            {
                                DTO.csreportgroupsInfo info = new DTO.csreportgroupsInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                                SetData(info);
                            }
                            EnableForm(true);
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "X":
                        Delete(ctr);

                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        RefreshList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            //DTO.csreportgroupsInfo info = new DTO.csreportgroupsInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            //DataTable dt = DTO.csreportgroupsInfo.ToDataTable();
                            //dt.Rows.Add(info.ToDataRow(dt));
                            //DataSet ds = new DataSet();
                            //ds.Tables.Add(dt);
                            //MainForm main = GetMainForm();
                            //if (main != null)
                            //    main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                _processStatus = strAction;
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }


        private void RefreshList()
        {
            GetMainForm().LoadDataTable(_strType);
            Rebind();
            if (layout == null)
                layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            layout.ResetLayout();
            layout.SetUpDGV(dgvList);
        }

        private void Delete(BUS.csreportgroupsControl ctr)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.csreportgroupsInfo info = new DTO.csreportgroupsInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                if (ctr.IsExist(_DB, info.ReportGroup))
                {
                    Forms.frmMsg frm = new Forms.frmMsg();
                    frm.FormClosed += delegate(object form, FormClosedEventArgs args)
                    {
                        if (((Gizmox.WebGUI.Forms.Form)form).DialogResult == DialogResult.OK)
                        {
                            BUS.csreportgroupdetailControl ctrdel = new BUS.csreportgroupdetailControl();
                            ctrdel.Deletes(_DB, info.ReportGroup);
                            sErr = ctr.Delete(_DB, info.ReportGroup);
                            if (sErr == "")
                            {
                                GetMainForm().RemoveRecord(_strType, ((DataRowView)dgvList.CurrentRow.DataBoundItem).Row);
                                EnableForm(false);
                                Rebind();
                                sErr = "Delete record " + info.ReportGroup + " successful";
                            }

                            ThrowMsg(sErr);

                        }

                    };
                    frm.ShowMsg("Do you want to delete " + info.ReportGroup + "?");

                }
                else
                    sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
            }
        }

        private void Save(BUS.csreportgroupdetailControl daogCtr, BUS.csreportgroupsControl ctr)
        {
            if (tabControl1.SelectedTab == tbDetail)
            {
                DTO.csreportgroupsInfo info = GetData();
                string[] arrrole = GetGroup();
                if (_processStatus == "A")
                {
                    sErr = daogCtr.Deletes(_DB, info.ReportGroup);
                    if (arrrole != null)
                    {
                        foreach (string role in arrrole)
                        {
                            DTO.csreportgroupdetailInfo daoginf = new DTO.csreportgroupdetailInfo();
                            daoginf.DB = _DB;
                            daoginf.reportgroup = info.ReportGroup;
                            daoginf.reportcode = role;
                            daogCtr.InsertUpdate(daoginf);
                        }
                    }
                    if (ctr.IsExist(_DB, info.ReportGroup))
                    {
                        sErr = ctr.Update(info);
                        UpdateRecord(info);
                        sErr = "Update record " + info.ReportGroup + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
                }
                else if (_processStatus == "C" || _processStatus == "O")
                {
                    sErr = daogCtr.Deletes(_DB, info.ReportGroup);
                    if (arrrole != null)
                    {
                        foreach (string role in arrrole)
                        {
                            DTO.csreportgroupdetailInfo daoginf = new DTO.csreportgroupdetailInfo();
                            daoginf.DB = _DB;
                            daoginf.reportgroup = info.ReportGroup;
                            daoginf.reportcode = role;
                            daogCtr.InsertUpdate(daoginf);
                        }
                    }
                    if (!ctr.IsExist(_DB, info.ReportGroup))
                    {
                        ctr.Add(info, ref sErr);
                        UpdateRecord(info);
                        sErr = "Add record " + info.ReportGroup + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0007", language);
                }
                ThrowMsg(sErr);

            }
        }

        private void UpdateRecord(DTO.csreportgroupsInfo info)
        {
            GetMainForm().GetTable(_strType).BeginLoadData();
            GetMainForm().UpdateRecord(_strType, info.ToDataRow(GetMainForm().GetTable(_strType)).ItemArray, LoadOption.OverwriteChanges);
            GetMainForm().GetTable(_strType).EndLoadData();
            EnableForm(false);
            Rebind();
        }
        private void Rebind()
        {
            bisDA.DataSource = GetMainForm().GetTable(_strType);
        }
        private void ThrowMsg(string sErr)
        {
            BaseForm x = this.Parent.Parent as BaseForm;
            if (x != null)
            {
                x.SetMsg(sErr);
            }
        }

        private DTO.csreportgroupsInfo GetData()
        {
            return new DTO.csreportgroupsInfo("TVC", txtDAG_ID.Text, txtNAME.Text, cboDA.Text, PODInfo.USER_ID, DateTime.Now, PODInfo.USER_ID, DateTime.Now

                );

        }

        private void EnableForm(bool p)
        {
            txtDAG_ID.ReadOnly = !p;
            txtNAME.ReadOnly = !p;
            cboDA.Enabled = p;
            libGroup.Enabled = p;
            libDataAccessGroup.Enabled = p;
            btnAdd.Enabled = p;
            btnClear.Enabled = p;
            btnFill.Enabled = p;
            btnRemove.Enabled = p;
        }

        private void SetData(DTO.csreportgroupsInfo info)
        {
            if (_isValueChange)
            {
                _isValueChange = false;
                txtDAG_ID.Text = info.ReportGroup;
                txtNAME.Text = info.Name;
                cboDA.Text = info.DAGid.ToString();
                SetGroup(info.ReportGroup);
                _isValueChange = true;
            }
        }

        private void RefreshForm(string str)
        {
            if (_isValueChange)
            {
                _isValueChange = false;
                txtDAG_ID.Text = str;
                txtNAME.Text = str;
                cboDA.Text = str;
                ClearGroup();
                _isValueChange = true;
            }
        }

        private string[] GetGroup()
        {
            if (libDataAccessGroup.Items.Count == 0)
                return null;
            string[] role = new string[libDataAccessGroup.Items.Count];
            for (int i = 0; i < libDataAccessGroup.Items.Count; i++)
            {
                ListViewItem item = libDataAccessGroup.Items[i];
                //((TextBox)((ListViewItem.ListViewSubControlItem)item.SubItems[4]).Control).Text;
                role[i] = ((Label)((ListViewItem.ListViewSubControlItem)item.SubItems[0]).Control).Text;
            }
            return role;
        }
        private void SetGroup(String ReportGroup)
        {
            libDataAccessGroup.Items.Clear();
            BUS.csreportgroupdetailControl ctr = new BUS.csreportgroupdetailControl();
            DataTable dt = ctr.GetbyGroup(_DB, ReportGroup, null, ref sErr);
            dt.DefaultView.Sort = "DESCRIPTN ASC";
            foreach (DataRow row in dt.Rows)
            {
                ListViewItem objItem = new ListViewItem();
                Label lbCode = new Label();
                lbCode.Text = row["reportcode"].ToString();
                lbCode.Name = "Description";
                lbCode.Tag = objItem;
                objItem.SubItems.Add(lbCode);
                objItem.Checked = false;
                Label txDescription = new Label();
                txDescription.Text = row["DESCRIPTN"].ToString();
                txDescription.Name = "Description";
                txDescription.Tag = objItem;
                objItem.SubItems.Add(txDescription);

                //if (libGroup.Items.Contains(objItem))
                //    libGroup.Items.Remove(objItem);

                for (int i = 0; i < libGroup.Items.Count; i++)
                {
                    ListViewItem objlibGroup = libGroup.Items[i] as ListViewItem;
                    if (((Label)((ListViewItem.ListViewSubControlItem)objlibGroup.SubItems[0]).Control).Text == row["reportcode"].ToString())
                    {
                        libGroup.Items.Remove(objlibGroup);
                    }
                }
                if (!libDataAccessGroup.Items.Contains(objItem))
                    libDataAccessGroup.Items.Add(objItem);
            }
        }
        private void ClearGroup()
        {
            libGroup.Items.Clear();
            BUS.LIST_QDControl qdCtr = new BUS.LIST_QDControl();
            DataTable dt = qdCtr.GetAll_LIST_QD("TVC", ref sErr);
            DataView dv = dt.DefaultView;
            dv.Sort = "DESCRIPTN ASC";
            //data = dv.ToTable();
            //dt.DefaultView.Sort = "DESCRIPTN desc";
            //libDataAccessGroup.Items.Clear();
            //dt.DefaultView.Sort = "DESCRIPTN DESC";
            foreach (DataRow row in dv.ToTable().Rows)
            {

                ListViewItem objItem = new ListViewItem();

                Label lbCode = new Label();
                lbCode.Text = row["QD_ID"].ToString();
                lbCode.Name = "Description";
                lbCode.Tag = objItem;
                objItem.SubItems.Add(lbCode);
                Label txDescription = new Label();
                txDescription.Text = row["DESCRIPTN"].ToString();
                txDescription.Name = "Description";
                txDescription.Tag = objItem;
                objItem.SubItems.Add(txDescription);
                //lvi.SubItems.Add("1");
                //libDataAccessGroup.Items.Remove(objItem);

                for (int i = 0; i < libDataAccessGroup.Items.Count; i++)
                {
                    ListViewItem objlibData = libDataAccessGroup.Items[i] as ListViewItem;
                    if (((Label)((ListViewItem.ListViewSubControlItem)objlibData.SubItems[0]).Control).Text == row["QD_ID"].ToString())
                    {
                        libDataAccessGroup.Items.Remove(objlibData);
                    }
                }
                if (!libGroup.Items.Contains(objItem))
                    libGroup.Items.Add(objItem);
                //if (!libGroup.Items.Contains(row["QD_ID"].ToString()))
                //    libGroup.Items.Add(row["QD_ID"].ToString());
            }
        }

        #endregion

        private void RGD_Load(object sender, EventArgs e)
        {
            if (!GetMainForm().IsContainsTables(_strType))
                GetMainForm().LoadDataTable(_strType);
            cboDA.Text = MainForm.PODInfo.Business_ID;
            LoadcboDA();
            //ClearGroup();
            //SetGroup(txtDAG_ID.Text.Trim());
            dgvList.AutoGenerateColumns = false;

            Rebind();
            EnableForm(false);
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            //layout.LoadLayout();
            layout.SetUpDGV(dgvList);
            RefreshForm("");
            //if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
            //    AllowEditLanguage();
        }

        private void LoadcboDA()
        {
            BUS.LIST_DAControl ctr = new BUS.LIST_DAControl();
            DataTable dt = ctr.GetAll(ref sErr);
            DataRow dr = dt.NewRow();
            dt.Rows.Add(dr);
            cboDA.DataSource = dt;
            cboDA.DisplayMember = "DAG_ID";
            cboDA.DisplayMember = "DAG_ID";
        }

        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.csreportgroupsInfo info = new DTO.csreportgroupsInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                SetData(info);
                EnableForm(false);
                tabControl1.SelectedTab = tbDetail;
                _processStatus = "V";
            }
        }

        private void btnFill_Click(object sender, EventArgs e)
        {
            for (int i = libGroup.Items.Count - 1; i >= 0; i--)
            {
                ListViewItem objItem = libGroup.Items[i] as ListViewItem;
                libGroup.Items.Remove(objItem);
                libDataAccessGroup.Items.Add(objItem);

            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {

            int icount = libGroup.CheckedItems.Count;
            if (libGroup.CheckedItems.Count > 0)
            {

                for (int i = icount - 1; i >= 0; i--)
                {
                    ListViewItem objItem = libGroup.CheckedItems[i] as ListViewItem;
                    objItem.Checked = false;
                    libGroup.Items.Remove(objItem);
                    libDataAccessGroup.Items.Add(objItem);


                }

            }
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (libDataAccessGroup.CheckedItems.Count > 0)
            {
                for (int i = libDataAccessGroup.CheckedItems.Count - 1; i >= 0; i--)
                {
                    ListViewItem objItem = libDataAccessGroup.CheckedItems[i] as ListViewItem;
                    objItem.Checked = false;
                    libDataAccessGroup.Items.Remove(objItem);
                    libGroup.Items.Add(objItem);

                }

            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            //int icount = libDataAccessGroup.Items.Count;
            for (int i = libDataAccessGroup.Items.Count - 1; i >= 0; i--)
            {
                ListViewItem objItem = libDataAccessGroup.Items[i] as ListViewItem;
                libDataAccessGroup.Items.Remove(objItem);
                libGroup.Items.Add(objItem);

            }
        }



        private void cboDB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_isValueChange)
            {
                _isValueChange = false;
                ClearGroup();
                SetGroup(txtDAG_ID.Text.Trim());
                _isValueChange = true;
            }
        }

    }
}
